package cn.edkuir.order.controller;

import cn.edkuir.order.entity.OrderEntity;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
public class TestMsgController {
    @Autowired
    private RabbitTemplate rabbitTemplate;


    @GetMapping("/sendMsg")
    public String sendMsg() {
        for(int i = 0; i < 10; i++) {
            OrderEntity orderEntity = new OrderEntity();
            orderEntity.setId((long) i);
            orderEntity.setMemberId(2L);
            //使用序列化机制将对象发送
            rabbitTemplate.convertAndSend("hello-java-exchange", "hello-java", orderEntity,
                    new CorrelationData(UUID.randomUUID().toString()));
        }

        return "ok";
    }

}
